﻿@using WXY.Course.Model;
@model IList<NoticeInfo>
@{
    var paras = this.Request.Params;
}
<div class="m_rtop">
    <h3>
        <label>
            内容管理
        </label>
        <span>></span>公告管理
    </h3>
</div>
<p class="m_ptop">
    @if (Model == null || Model.Count < 10)
    {
        <input type="button" id="btnAdd" class="btn_bg1" value="新增公告">
    }
    <span style="color:red;font-size:12px;">最多添加10条</span>
</p>
<div class="m_box">
    <table width="980" cellpadding="0" cellspacing="0" border="1"
           class="tab1">
        <tr>
            <th width="150">操作</th>
            <th width="80">公告ID</th>
            <th max-width="300">公告内容</th>
            <th width="140">是否启用</th>
            <th width="140" scope="col">创建时间</th>
            <th width="140" scope="col">更新时间</th>
            <th width="140" scope="col">最后编辑人</th>
        </tr>
        @if (Model != null)
        {
            int index = 0;
            foreach (var item in Model)
            {
                index++;
                <tr>
                    <td align="center">
                        <input type="hidden" class="js_code" value="@item.Code">
                        <a href="@Url.Action("Edit", "Notice", new { Id = item.Code})" name="editLink">编辑</a>
                        <a href="javascript:void(0)" name="deleteLink">删除</a>
                        @if (!item.IsActive)
                        {
                            <a href="javascript:void(0)" name="activeLink">启用</a>
                        }
                    </td>
                    <td align="center">@item.Code</td>
                    <td>@item.Content</td>
                    <td>@(item.IsActive ? "已启用" : "未启用")</td>
                    <td>@item.CreateTime</td>
                    <td>@item.UpdateTime</td>
                    <td align="center">@item.UpdateUser.RealName</td>
                </tr>
            }
        }
    </table>
</div>

<script type="text/javascript">
    $(function () {
        $("#btnAdd").on("click", function () {
            location.href = "@Url.Action("Edit", "Notice")";
        });
       
        $("a[name='activeLink']").on("click", function () {
            var e = this;
            var actName = $(e).html();
            art.dialog({
                lock: true,
                title: '提示',
                content: '确定要' + actName + '该公告么？',
                button: [
                    {
                        value: '确定',
                        callback: function () {
                            var id = $(e).parent().find("input.js_code").val();
                            $.ajax({
                                type: 'post',
                                url: '@Url.Action("Active", "Notice")',
                                data: { id: id },
                                success: function (data) {
                                    if (data.IsSuccess && data.Data > 0) {
                                        art.dialog({
                                            lock: true,
                                            title: '提示',
                                            content: actName + '成功',
                                            ok: function () { location.reload(); }
                                        });
                                    } else {
                                        art.dialog({
                                            lock: true,
                                            title: '提示',
                                            content: actName + "失败" + data.Message,
                                            ok: function () {
                                                this.close();
                                            }
                                        });
                                    }
                                }
                            });
                        }
                    },
                    {
                        value: '取消',
                        focus: true,
                        callback: function () {
                            this.close();
                        }
                    }
                ]
            });
        });
        $("a[name='deleteLink']").on("click", function () {
            var e = this;
            art.dialog({
                lock: true,
                title: '提示',
                content: '确定要删除该公告么？',
                button: [
                    {
                        value: '确定',
                        callback: function () {
                            var id = $(e).parent().find("input.js_code").val();
                            $.ajax({
                                type: 'post',
                                url: '@Url.Action("Delete","Notice")',
                                data: { id: id },
                                success: function (data) {
                                    if (data.IsSuccess && data.Data > 0) {
                                        art.dialog({
                                            lock: true,
                                            title: '提示',
                                            content: '删除成功',
                                            ok: function () { location.reload(); }
                                        });
                                    } else {
                                        art.dialog({
                                            lock: true,
                                            title: '提示',
                                            content: "删除失败" + data.Message,
                                            ok: function () {
                                                this.close();
                                            }
                                        });
                                    }
                                }
                            });
                        }
                    },
                    {
                        value: '取消',
                        focus: true,
                        callback: function () {
                            this.close();
                        }
                    }
                ]
            });
        });
    });
</script>
